<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>商店设置</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		var classifies = new Array();
		$(document).ready(function() {
			$("#inputForm").validate({
				submitHandler: function(form){
					if($("#logoUrl").val()==""){
						showJBoxMess("请上传商店封面.","error");
						return;
					}
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
			// 定义一个新的复制对象
			var clip = new ZeroClipboard($("a[id='clip_button']"), {
			  moviePath: "${ctxStatic }/ZeroClipboard/ZeroClipboard.swf"
			} );
			
			// 复制内容到剪贴板成功后的操作
			clip.on( 'complete', function(client, args) {
			   alert("复制成功，请到剪贴板粘帖！");
			} );
			
			if(${fn:length(fns:getClassifyOneList())}>0){  //加载进来时封装商品信息
				classifies = new Array();
				<c:forEach items="${fns:getClassifyOneList()}" var="classify" varStatus="vs">
					var item = new Object();
					item.id="${classify.id}";
					item.name="${classify.name}";
					item.shopUrl="${classify.shopUrl}";
					classifies.push(item);
				</c:forEach>
			}
		});
		
		function showPhoto(path){
			$("#logoUrl").val(path);
			$("#cutPhoto").css("display", "block");
			var imageSrc = '${ctx}/download?filePath='+path;
			$("#cutPhoto").attr("src", imageSrc);
		}
		
		function changeClassify(obj){
			if($(obj).val()==""){
				$("#shopUrl").val("");
			}else{
				for(var i=0; i<classifies.length; i++){
					if($(obj).val()==classifies[i].id){
						$("#shopUrl").val(classifies[i].shopUrl); break;
					}
				}
			}
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/ivm/business/hangstore/list">&nbsp;商店设置</a></li>
		<li class="active"><a href="${ctx}/ivm/business/hangstore/form?id=${hangStore.id}">商店<shiro:hasPermission name="ivm:business:hangstore:edit">${not empty hangStore.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="ivm:business:hangstore:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="hangStore" action="${ctx}/ivm/business/hangstore/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<form:hidden path="merchant.id"/>
		<tags:message content="${message}"/>
		<div class="control-group">
			<label class="control-label"><span class="color-red font-size20">*</span>选择商店:</label>
			<div class="controls">
				<c:set var="isExists" value="false"/>
				<form:select id="classify" path="classify.id" class="required" onchange="changeClassify(this)">
					<form:option value="" label="请选择"/>
					<c:forEach items="${fns:getClassifyOneList()}" var="classify">
						<c:forEach items="${choicedList}" var="hs">
							<c:if test="${classify.id==hs.classify.id}">
								<c:set var="isExists" value="true"/>
							</c:if>
						</c:forEach>
						<c:if test="${isExists==false}">
							<form:option value="${classify.id}" label="${classify.name}"/>
						</c:if>
						<c:set var="isExists" value="false"/>
					</c:forEach>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><span class="color-red font-size20">*</span>商店封面:</label>
			<div class="controls">
				<form:hidden path="logoUrl" class="required"/>
				<div class="photo" style="width:149px; height:84px;">
					<c:if test="${hangStore.logoUrl!=null && hangStore.logoUrl!=''}">
						<img id="cutPhoto" src="${ctx}/download?filePath=${hangStore.logoUrl }" style="width:149px; height:84px;" />
					</c:if>
					<c:if test="${hangStore.logoUrl==null || hangStore.logoUrl==''}">
						<img id="cutPhoto" src="" style="width:149px; height:84px;" />
					</c:if>
				</div>
				<a href="javascript:" class="btn" id="cutPhotoUpload">上传图片</a>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><span class="color-red font-size20">*</span>链接地址:</label>
			<div class="controls">
				<form:input id="shopUrl" path="classify.shopUrl" readonly="true" htmlEscape="false" maxlength="200" cssStyle="width: 400px;" class="required" title="${hangStore.classify.shopUrl}"/>
				<a href="javascript:" class="btn" id="clip_button" data-clipboard-target="shopUrl">复制</a>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><span class="color-red font-size20">*</span>状态:</label>
			<div class="controls">
				<form:radiobuttons path="status" items="${fns:getDictList('roll_status')}" itemLabel="label" itemValue="value" htmlEscape="false" class="required" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><span class="color-red font-size20">*</span>排序:</label>
			<div class="controls">
				<form:input path="sort" htmlEscape="false" maxlength="50" class="required digits"/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="ivm:business:hangstore:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>
